package com.itheima.controller.admin;

import com.itheima.common.result.PageResult;
import com.itheima.common.result.Result;
import com.itheima.dto.YddCatePageQueryDTO;
import com.itheima.pojo.YddCate;
import com.itheima.service.YddCateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_cate")
@Api("分页管理")
public class YddCateController {

    @Autowired
    YddCateService yddCateService;

    /**
     * 分类管理-分页查询
     * @param dto
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分类列表-分页")
    public Result<PageResult> list(YddCatePageQueryDTO dto){
        PageResult pageResult = yddCateService.pageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 分类详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("分类详情")
    public Result rowInfoCate(Integer id){
        YddCate yddCate = yddCateService.rowInfoCate(id);
        return Result.success(yddCate);
    }

    /**
     * 分类修改
     * @param yddCate
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("分类修改")
    public Result updateCate(@RequestBody YddCate yddCate){
        yddCateService.updateById(yddCate);
        return Result.success();
    }

    /**
     * 分类删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("分类删除")
    public Result delCate(String id){
        yddCateService.removeById(id);
        return Result.success();
    }

    /**
     * 分类添加
     * @param yddCate
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("分类添加")
    public Result addCate(@RequestBody YddCate yddCate){
        yddCateService.save(yddCate);
        return Result.success();
    }

    /**
     * 分类列表-全部
     * @return
     */
    @GetMapping("all")
    @ApiOperation("分类列表-全部")
    public Result allCate(){
        return yddCateService.allCate();
    }
}
